package com.huijinhui.wlmtsys.controller;


import com.huijinhui.wlmtsys.enums.AppHttpCodeEnum;
import com.huijinhui.wlmtsys.pojo.dtos.PageDTO;
import com.huijinhui.wlmtsys.pojo.dtos.ResponseResult;
import com.huijinhui.wlmtsys.pojo.entity.NewsPageQuery;
import com.huijinhui.wlmtsys.pojo.entity.PageQuery;
import com.huijinhui.wlmtsys.pojo.entity.WlmtsysNews;
import com.huijinhui.wlmtsys.pojo.entity.WlmtsysProject;
import com.huijinhui.wlmtsys.service.NewsService;
import com.huijinhui.wlmtsys.service.ProjectsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "admin---项目介绍接口")
@RestController
@RequestMapping("/project")
@RequiredArgsConstructor
@Slf4j
public class ProjectsController {

    @Autowired
    private ProjectsService projectsService;


    @Operation(summary = "admin---新增项目接口")
    @PostMapping("/save")
    public void addProject(@RequestBody WlmtsysProject project) {
        log.info("新增项目接口");
        projectsService.saveProject(project);
    }

    @Operation(summary = "admin---删除项目接口")
    @DeleteMapping("/delete/{id}")
    public void deleteProject(@PathVariable Integer id) {
        log.info("删除项目接口");
        projectsService.deleteProject(id);
    }

    @Operation(summary = "admin---修改项目接口")
    @PutMapping("/update")
    public void updateProject(@RequestBody WlmtsysProject project) {
        log.info("修改项目接口");
        projectsService.updateProject(project);
    }
    @Operation(summary = "admin---项目分页查询接口")
    @GetMapping("/page")
    public PageDTO<WlmtsysProject> queryNewsPage(PageQuery query) {
        log.info("项目分页查询接口");
        return projectsService.queryProjectPage(query);
    }


    @Operation(summary = "admin---项目详情查询接口")
    @GetMapping("/{id}")
    public ResponseResult getProject(@PathVariable Integer id) {
        log.info("项目详情查询接口,id:{}", id);
        WlmtsysProject project = projectsService.getProject(id);
        return ResponseResult.okResult(project);
    }

    @PostMapping("/upload")
    public ResponseResult uploadNews(@RequestParam("file") MultipartFile multipartFile, @RequestParam("id") Integer projectId) {
        log.info("图片接口,{},id:{}", multipartFile, projectId);
        projectsService.uploadNews(multipartFile, projectId);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }


    @Operation(summary = "项目查询接口")
    @GetMapping("/list")
    public ResponseResult getProjectList() {
        log.info("项目查询接口");
        List<WlmtsysProject> list = projectsService.getProjectList();
        return ResponseResult.okResult(list);
    }


}

